﻿using System;
using SharpSqlAnalyzer.stmt;

namespace SharpSqlAnalyzer.nodes
{
	// Token: 0x02000327 RID: 807
	public class TOrderByItem : TParseTreeNode
	{
		// Token: 0x170006B2 RID: 1714
		// (get) Token: 0x06001CE5 RID: 7397 RVA: 0x00332440 File Offset: 0x00330640
		// (set) Token: 0x06001CE6 RID: 7398 RVA: 0x00332448 File Offset: 0x00330648
		public ENullOrder NullOrder
		{
			get
			{
				return this._nullOrder;
			}
			set
			{
				this._nullOrder = value;
			}
		}

		// Token: 0x06001CE7 RID: 7399 RVA: 0x00332451 File Offset: 0x00330651
		public void setNullOrderByToken(TSourceToken nullOrder)
		{
			if (nullOrder == null)
			{
				return;
			}
			if (nullOrder.ToString().Equals("first", StringComparison.CurrentCultureIgnoreCase))
			{
				this._nullOrder = ENullOrder.nullsFirst;
				return;
			}
			if (nullOrder.ToString().Equals("last", StringComparison.CurrentCultureIgnoreCase))
			{
				this._nullOrder = ENullOrder.nullsLast;
			}
		}

		// Token: 0x06001CE8 RID: 7400 RVA: 0x0033248C File Offset: 0x0033068C
		public void setSortTypeByToken(TSourceToken st)
		{
			this.SortTypeByToken = st;
		}

		// Token: 0x170006B3 RID: 1715
		// (get) Token: 0x06001CE9 RID: 7401 RVA: 0x00332495 File Offset: 0x00330695
		// (set) Token: 0x06001CEA RID: 7402 RVA: 0x0033249D File Offset: 0x0033069D
		public virtual ESortType SortOrder
		{
			get
			{
				return this.sortOrder;
			}
			set
			{
				this.sortOrder = value;
			}
		}

		// Token: 0x170006B4 RID: 1716
		// (get) Token: 0x06001CEC RID: 7404 RVA: 0x003324AF File Offset: 0x003306AF
		// (set) Token: 0x06001CEB RID: 7403 RVA: 0x003324A6 File Offset: 0x003306A6
		public virtual TExpression SortKey
		{
			get
			{
				return this.sortKey;
			}
			set
			{
				this.sortKey = value;
			}
		}

		// Token: 0x06001CED RID: 7405 RVA: 0x003324B7 File Offset: 0x003306B7
		public virtual void TOrderByItem_Renamed()
		{
		}

		// Token: 0x170006B5 RID: 1717
		// (get) Token: 0x06001CEE RID: 7406 RVA: 0x003324B9 File Offset: 0x003306B9
		// (set) Token: 0x06001CEF RID: 7407 RVA: 0x003324C1 File Offset: 0x003306C1
		public virtual int SortType
		{
			get
			{
				return this.sortType;
			}
			set
			{
				this.sortType = value;
			}
		}

		// Token: 0x170006B6 RID: 1718
		// (set) Token: 0x06001CF0 RID: 7408 RVA: 0x003324CC File Offset: 0x003306CC
		public virtual TSourceToken SortTypeByToken
		{
			set
			{
				if (value == null)
				{
					return;
				}
				if (value.astext.Equals("asc", StringComparison.CurrentCultureIgnoreCase))
				{
					this.sortType = 1;
					this.sortOrder = ESortType.asc;
					return;
				}
				if (value.astext.Equals("desc", StringComparison.CurrentCultureIgnoreCase))
				{
					this.sortType = 2;
					this.sortOrder = ESortType.desc;
				}
			}
		}

		// Token: 0x06001CF1 RID: 7409 RVA: 0x00332520 File Offset: 0x00330720
		public override void init(object arg1)
		{
			this.sortKey = (TExpression)arg1;
		}

		// Token: 0x06001CF2 RID: 7410 RVA: 0x00332530 File Offset: 0x00330730
		public override void doParse(TCustomSqlStatement psql, ESqlClause plocation)
		{
			if (this.sortKey != null)
			{
				if (psql != null && psql is TSelectSqlStatement && this.sortKey.ExpressionType == EExpressionType.simple_object_name_t && this.sortKey.ObjectOperand.PartToken != null && this.sortKey.ObjectOperand.ObjectToken == null && psql.ResultColumnList != null)
				{
					for (int i = 0; i < psql.ResultColumnList.size(); i++)
					{
						TResultColumn resultColumn = psql.ResultColumnList.getResultColumn(i);
						if (resultColumn.AliasClause != null && resultColumn.AliasClause.AliasName.ToString().Equals(this.sortKey.ToString(), StringComparison.CurrentCultureIgnoreCase))
						{
							this.sortKey.ObjectOperand.ObjectType = 2;
							break;
						}
					}
				}
				this.sortKey.doParse(psql, ESqlClause.orderby);
			}
		}

		// Token: 0x06001CF3 RID: 7411 RVA: 0x00332604 File Offset: 0x00330804
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x06001CF4 RID: 7412 RVA: 0x00332614 File Offset: 0x00330814
		public override void acceptChildren(TParseTreeVisitor v)
		{
			v.preVisit(this);
			if (this.sortKey != null)
			{
				this.sortKey.acceptChildren(v);
			}
			v.postVisit(this);
		}

		// Token: 0x04001A8A RID: 6794
		private ENullOrder _nullOrder;

		// Token: 0x04001A8B RID: 6795
		private ESortType sortOrder;

		// Token: 0x04001A8C RID: 6796
		private TExpression sortKey;

		// Token: 0x04001A8D RID: 6797
		private int sortType;
	}
}
